public class ConstantCurrent extends ParameterFramework implements IAppliedCurrent {
    private double strength ;
    private double currentStart = Double.NEGATIVE_INFINITY ;
    private double currentStop = Double.POSITIVE_INFINITY ;
    
    public String getParam( String name ) {
        if ( name.equals( "currentStrength" ) ) {
            return "" + strength ;
        } else if ( name.equals( "currentStart" ) ) {
            return "" + currentStart ;
        } else if ( name.equals( "currentStop" ) ) {
            return "" + currentStop ;
        } else {
            return null ;
        }
    }
    
    public void setParam( String name , String data ) {
        double value ;
        // all parameters are doubles
        try {
            value = Double.parseDouble( data ) ;
        } catch ( NumberFormatException e ) {
            // not a double; ignore the set request
            return ;
        }
        if ( name.equals( "currentStrength" ) ) {
            strength = value ;
        } else if ( name.equals( "currentStart" ) ) {
            currentStart = value ;
        } else if ( name.equals( "currentStop" ) ) {
            currentStop = value ;
        }
    }
    public String getName( ) {
        return "Constant Current" ;
    }
    
    public ConstantCurrent( double strength ) {
        String [ ] params = { "currentStart" , "currentStop" , "currentStrength" } ;
        parameterNames = params ;
        this.strength = strength ;
    }
    
    public IAppliedCurrent clone( ) {
        ConstantCurrent c = new ConstantCurrent( strength ) ;
        c.setParam( getParams( ) ) ;
        return c ;
    }
    
    public double amount( double t ) {
        if ( t >= currentStart && t <= currentStop ) {
            return strength ;
        } else {
            return 0 ;
        }
    }
}
